home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / exec / createpool.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  3KB  |  118 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: createpool.c,v 1.4 1996/08/13 13:56:00 digulla Exp $
  4.     $Log: createpool.c,v $
  5.     Revision 1.4  1996/08/13 13:56:00  digulla
  6.     Replaced __AROS_LA by __AROS_LHA
  7.     Replaced some __AROS_LH*I by __AROS_LH*
  8.     Sorted and added includes
  9.  
  10.     Revision 1.3  1996/08/01 17:41:09  digulla
  11.     Added standard header for all files
  12.  
  13.     Desc:
  14.     Lang:
  15. */
  16. #include "exec_intern.h"
  17. #include <aros/libcall.h>
  18. #include <clib/alib_protos.h>
  19. #include "machine.h"
  20. #include "memory.h"
  21.  
  22. #define NEWLIST(l) \
  23. ((l)->lh_Head=(struct Node *)&(l)->lh_Tail, \
  24.  (l)->lh_Tail=NULL,                         \
  25.  (l)->lh_TailPred=(struct Node *)(l))
  26.  
  27. /*****************************************************************************
  28.  
  29.     NAME */
  30.     #include <exec/memory.h>
  31.     #include <clib/exec_protos.h>
  32.  
  33.     __AROS_LH3(APTR, CreatePool,
  34.  
  35. /*  SYNOPSIS */
  36.     __AROS_LHA(ULONG, requirements, D0),
  37.     __AROS_LHA(ULONG, puddleSize,   D1),
  38.     __AROS_LHA(ULONG, threshSize,   D2),
  39.  
  40. /*  LOCATION */
  41.     struct ExecBase *, SysBase, 116, Exec)
  42.  
  43. /*  FUNCTION
  44.     Create a private pool for memory allocations.
  45.  
  46.     INPUTS
  47.     requirements - The type of the memory
  48.     puddleSize   - The number of bytes that the pool expands
  49.                if it is too small.
  50.     threshSize   - Allocations beyond the threshSize are given
  51.                directly to the system. threshSize must not
  52.                be smaller than the puddleSize.
  53.  
  54.     RESULT
  55.     A handle for the memory pool or NULL if the pool couldn't
  56.     be created
  57.  
  58.     NOTES
  59.  
  60.     EXAMPLE
  61.     \* Get the handle to a private memory pool *\
  62.     po=CreatePool(MEMF_ANY,16384,8192);
  63.     if(po!=NULL)
  64.     {
  65.         \* Use the pool *\
  66.         UBYTE *mem1,*mem2;
  67.         mem1=AllocPooled(po,1000);
  68.         mem2=AllocPooled(po,2000);
  69.         \* Do something with the memory... *\
  70.  
  71.         \* Free everything at once *\
  72.         DeletePool(po);
  73.     }
  74.  
  75.     BUGS
  76.  
  77.     SEE ALSO
  78.     DeletePool(), AllocPooled(), FreePooled()
  79.  
  80.     INTERNALS
  81.  
  82.     HISTORY
  83.     16-10-95    created by m. fleischer
  84.  
  85. ******************************************************************************/
  86. {
  87.     __AROS_FUNC_INIT
  88.  
  89.     struct Pool *pool=NULL;
  90.  
  91.     /* puddleSize must not be smaller than threshSize */
  92.     if(puddleSize>=threshSize)
  93.     {
  94.     /* Round puddleSize up to be a multiple of MEMCHUNK_TOTAL. */
  95.     puddleSize=(puddleSize+MEMCHUNK_TOTAL-1)&~(MEMCHUNK_TOTAL-1);
  96.  
  97.     /*
  98.         Allocate memory for the Pool structure using the same requirements
  99.         as for the whole pool (to make it shareable, residentable or
  100.         whatever is needed).
  101.     */
  102.     pool=(struct Pool *)AllocMem(sizeof(struct Pool),requirements);
  103.     if(pool!=NULL)
  104.     {
  105.         /* Clear the lists */
  106.         NEWLIST((struct List *)&pool->PuddleList);
  107.         NEWLIST((struct List *)&pool->BlockList );
  108.  
  109.         /* Set the rest */
  110.         pool->Requirements=requirements;
  111.         pool->PuddleSize  =puddleSize;
  112.         pool->ThreshSize  =threshSize;
  113.     }
  114.     }
  115.     return pool;
  116.     __AROS_FUNC_EXIT
  117. } /* CreatePool */
  118.